﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Factories;
using FarseerPhysics.SamplesFramework;

namespace BattleToast
{
    public class AnimatedGameObject : GameObject
    {
        private int currentFrame;
        private Microsoft.Xna.Framework.Rectangle recta;
        private float speed;
        private float timer = 0f;
        private float interval = 200f;

        public int CurrentFrame
        {
            get { return currentFrame; }
            set { currentFrame = value; }
        }

        public Microsoft.Xna.Framework.Rectangle Recta
        {
            get { return recta; }
            set { recta = value; }
        }

        public float Speed
        {
            get { return speed; }
            set { speed = value; }
        }

        public AnimatedGameObject() { }

        public AnimatedGameObject(World world, Texture2D texture, Vector2 position, Vector2 size, int currentFrame)
            : base(texture)
        {
            this.currentFrame = currentFrame;
        }

        public void SpriteAnimate(GameTimerEventArgs gTime, int k, float speed)
        {
            this.Recta = new Microsoft.Xna.Framework.Rectangle(currentFrame * (int)this.Size.X, 0, (int)this.Size.X, (int)this.Size.Y);
            
            timer += (float)gTime.ElapsedTime.TotalMilliseconds*speed;

            if (timer > interval)
            {
                currentFrame++;
                if (currentFrame > k)
                {
                    currentFrame = 0;
                }
                timer = 0f;
            }
        }

        public void MoveForward()
        {
            this.Body.Position = new Vector2(this.Body.Position.X - speed, this.Body.Position.Y);
        }


    }
}
